#!/usr/bin/env python
#-*- coding:utf-8 -*-

# file:insecure_courseResource.py
# author:86133
# datetime:2022/6/9 9:41
# software: PyCharm
'''
this is functiondescription
'''
from flask_restful import Resource, reqparse
from flask import jsonify

from app.api_1_0 import limiter
from app.controller.courseController import CourseController
from app.utils import commons
from app.utils.response_code import RET



class InsecureCourseResource(Resource):

    # get
    @classmethod
    @limiter.exempt
    def get(cls, courseID=None):
        if courseID:
            kwargs = {
                'courseID': courseID
            }

            res = CourseController.get(**kwargs)
            if res['code'] == RET.OK:
                return jsonify(code=res['code'], message=res['message'], data=res['data'])
            else:
                return jsonify(code=res['code'], message=res['message'], data=res['data'])

        parser = reqparse.RequestParser()
        parser.add_argument('courseName', location='args', required=False, help='courseName参数类型不正确或缺失')
        parser.add_argument('teacherID', location='args', required=False, help='teacherID参数类型不正确或缺失')
        parser.add_argument('count', location='args', required=False, help='count参数类型不正确或缺失')
        parser.add_argument('credit', location='args', required=False, help='credit参数类型不正确或缺失')
        parser.add_argument('addTime', location='args', required=False, help='addTime参数类型不正确或缺失')

        parser.add_argument('Page', location='args', required=False, help='Page参数类型不正确或缺失')
        parser.add_argument('Size', location='args', required=False, help='Size参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        res = CourseController.get(**kwargs)
        if res['code'] == RET.OK:
            return jsonify(code=res['code'], message=res['message'], data=res['data'], totalPage=res['totalPage'],
                           totalCount=res['totalCount'])
        else:
            return jsonify(code=res['code'], message=res['message'], data=res['data'])